Package nz.ac.massey.softwarec.group3.game

Source Code of nz.ac.massey.softwarec.group3.game.GameTest

package nz.ac.massey.softwarec.group3.game;

import nz.ac.massey.softwarec.group3.game.map.MapConnection;
import nz.ac.massey.softwarec.group3.game.map.MapStation;
import nz.ac.massey.softwarec.group3.game.map.MapDeveloper;
import java.util.ArrayList;
import java.util.List;
import nz.ac.massey.softwarec.group3.game.map.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Natalie
*/
public class GameTest {
   
    private List<Player> players;
    private Player player;
    private Game testing;
    private Map map;
    private Boolean playing;
    private String mapXMLtest, mapJSONtest;
    private List<Move> mrXMoves;
    private MrX mrX;
    private MapDeveloper mapDevelopment;
    private List<MapStation> mapNodes;
    MapStation mapst1, mapst2, mapst3, mapst4;
    List<MapConnection> connections;
    List<MapStation> mapstations;
   
   
    public GameTest() {
    }
   
    @Before
    public void setUp() {
       testing = new Game("group3scotlandyard@gmail.com", 1);
       players = new ArrayList<Player>();
       playing = false;
       mapXMLtest = "<?xml version='1.0' encoding='UTF-8'?> <map><intersections></intersections></map>";
       map = new Map(mapXMLtest);
       mrXMoves = new ArrayList<Move>();
       mapDevelopment = new MapDeveloper();
       mapNodes = mapDevelopment.developMap(mapXMLtest);
       mapJSONtest = map.createJSONString(mapNodes);
       mapst1 = new MapStation(0, 1.0, 1.0);
       mapst2 = new MapStation(1, 2.0, 2.0);
       mapst3 = new MapStation(2, 3.0, 3.0);
       mapst4 = new MapStation(1, 4.0, 4.0);
      
    }
   
    @After
    public void tearDown() {
        testing = null;
        players = null;
        playing = false;
    }

    /**
     * Test of getCreatorEmail method, of class Game.
     */
    @Test
    public void testGetCreatorEmail() {
        System.out.println("getCreatorEmail");
        String expResult = "group3scotlandyard@gmail.com";
        String result = testing.getCreatorEmail();
        assertEquals(expResult, result);
    }

    /**
     * Test of getMap & setMap method, of class Game.
     */
    @Test
    public void testGetMap() {
        System.out.println("getMap & setMap");
        testing.setMap(map);
        Map expResult = map;
        Map result = testing.getMap();
        assertEquals(expResult, result);
    }

    /**
     * Test of getGameID method, of class Game.
     */
    @Test
    public void testGetGameID() {
        System.out.println("getGameID");
        int expResult = 1;
        int result = testing.getGameID();
        assertEquals(expResult, result);
    }

    /**
     * Test of getWhosTurn & setWhosTurn method, of class Game.
     */
    @Test
    public void testGetWhosTurn() {
        System.out.println("getWhosTurn & setWhosTurn");
        int expResult = 3;
        testing.setWhosTurn(3);
        int result = testing.getWhosTurn();
        assertEquals(expResult, result);
    }

    /**
     * Test of getPlayers and addUserToGame methods, of class Game.
     */
    @Test
    public void testGetPlayers() {
        System.out.println("getPlayers & addUserToGame");
        testing.addUserToGame("natalieeustace@gmail.com");
        List expResult = new ArrayList();
        expResult.add(testing.getPlayer("group3scotlandyard@gmail.com"));
        expResult.add(testing.getPlayer("natalieeustace@gmail.com"));
        List result = testing.getPlayers();
        assertEquals(expResult, result);
    }

    /**
     * Test of getPlayer method, of class Game.
     */
    @Test
    public void testGetPlayer() {
        System.out.println("getPlayer");
        Player expResult = null;
        Player result = testing.getPlayer("testingemail@gmail.com");
        assertEquals(expResult, result);
    }

    /**
     * Test of checkIfUserIsInGameAlready method, of class Game.
     */
    @Test
    public void testCheckIfUserIsInGameAlready() {
        System.out.println("checkIfUserIsInGameAlready");
        String userEmail = "group3scotlandyard@gmail.com";
        boolean expResult = true;
        boolean result = testing.checkIfUserIsInGameAlready(userEmail);
        assertEquals(expResult, result);
    }
   

    /**
     * Test of removeUserFromGame method if users email isn't there, of class Game.
     */
    @Test
    public void testRemoveUserFromGame() {
        System.out.println("removeUserFromGame");
        String email = "group3scotlandyard@gmail.com";
        boolean expResult = true;
        boolean result = testing.removeUserFromGame(email);
        assertEquals(expResult, result);
    }
   
    /**
     * Test of removeUserFromGame method if users email isn't there, of class Game.
     */
    @Test
    public void testRemoveUserFromGame2() {
        System.out.println("removeUserFromGame2");
        String email = "thisshouldfail@gmail.com";
        boolean expResult = false;
        boolean result = testing.removeUserFromGame(email);
        assertEquals(expResult, result);
    }

    /**
     * Test of isPlaying & setPlaying methods, of class Game.
     */
    @Test
    public void testIsPlaying() {
        System.out.println("isPlaying & setPlaying");
        testing.setPlaying(true);
        boolean expResult = true;
        boolean result = testing.isPlaying();
        assertEquals(expResult, result);
    }
   
    /**
     * Test of getCreatorName and setCreatorName methods of class Game.
     */
    public @Test void testGetCreatorName(){
        System.out.println("getCreatorName & setCreatorName");
        testing.setCreatorName("Tester");
        String expResult = "Tester";
        String result = testing.getCreatorName();
       
        assertEquals(expResult, result);
    }
   
    /**
     * Test of mrXMoves method of Game class.
     */
    public @Test void testMrXMoves(){
        System.out.println("mrXMoves");
        Move move = new Move("Bus", 1, 2);
        mrXMoves.add(move);
        List<Move> result = testing.getMrXMoves();
        List<Move> expResult = new ArrayList<Move>();
        expResult.add(move);
        assertEquals(expResult, result);
    }
   
    /**
     * Test of getMrX method of Game class.
     */
    public @Test void testGetMrX(){
        System.out.println("getMrX");
       
        MrX result = testing.getMrX();
        MrX expResult = mrX;
       
        assertEquals(expResult, result);
    }
   
    /**
     * Trying to increase coverage by getting rid of private methods called here
     * that aren't being tested.
     */
    public @Test void testStartGame(){
       
        testing.addUserToGame("natalieeustace@gmail.com");
        testing.setMap(map);
        mapNodes.add(mapst1);
        mapNodes.add(mapst2);
        mapNodes.add(mapst3);      
        mapNodes.add(mapst4);
        mapstations = new ArrayList();
        mapstations.add(mapst1);
        mapstations.add(mapst2);
        mapstations.add(mapst3);
        mapstations.add(mapst4);
        map.createJSONString(mapstations);
        testing.addUserToGame("group3scotlandyard@gmail.com");
        testing.addUserToGame("natalieeustace@gmail.com");
        testing.addUserToGame("akatsukinazo@gmail.com");
        testing.addUserToGame("robertsilberbauer@hotmail.com");
        System.out.println("Map Stations : " +map.getMapStations());

        testing.startGame();
    }
}
TOP

Related Classes of nz.ac.massey.softwarec.group3.game.GameTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.